// 引用自写koa.ja
const koa = require('koa');
const packageJson = require('./package.json');
console.log('packageJson:');
// console.log(packageJson);
// const koa = require('./koa');
// console.log('require:');
// console.log(require);
// console.log('module:')
// console.log(module);
var app = new koa();
var port = 3000;

app.use(async (ctx,next)=>{
    console.log('ctx.status: '+ctx.status);
    // console.log(ctx.body);
    // console.log(ctx.message);
    let start_t = Date.now();
    // await next();
    let end_t = Date.now();
    // console.log(Object.keys(ctx.req));
    // console.log(Object.keys(ctx.res));
    console.log(`${ctx.req.method} ${ctx.req.url} ${end_t-start_t}ms`);
    
    // ctx.body='Hello world';
});

app.use((ctx,next)=>{
    for(var i=0;i<10000;i++){
    }
    // ctx.body='Hello world';
    // setTimeout(()=>{
    //     next();
    // }, 1000);
    console.log(ctx.body);
})

app.listen(port, ()=>{
    console.log(`Server is running on http://127.0.0.1:${port}`);
})

// setTimeout(()=>{
//     console.log(`loaded: ${module.loaded}`);
// },100);

let res = module.load('./test.js');
// let ext = findLongestRegisteredExtension('./test.js')

// module._compile('function() hi{console.log("good")}; module.exports=hi; hi(); ');
// require.resolve('webpack');
try{
    require.resolve('webpack');
}catch(e){
    console.log('文件不存在');
    throw e;
}